﻿@using BlueLight.Server.Models
@using RuoVea.ExUtil
@using RuoVea.OmiApi.Dict.Entitys
@using RuoVea.OmiApi.Dict.Service
@using RuoVea.ExEnum
@using RuoVea.ExSugar.Entity;
@using RuoVea.OmiApi.Article.Service
@using RuoVea.OmiApi.Article.Service.Dto
@inject SysDictTypeService _sysDictTypService;
@inject ArticleService _articleService;
@{
    // 首页大图
    SysDictValue? banner = (await _sysDictTypService.GetTypeAndDataByCodeAsync("BANNER"))?.Children?.FirstOrDefault();

    // 从URL中提取ID
    var currentPath = Context.Request.Path.Value??"";
    long? currentArticleId = null;

    if (currentPath.StartsWith("/details/") && currentPath.EndsWith(".html"))
    {
        var idString = currentPath.Replace("/details/", "").Replace(".html", "");
        if (long.TryParse(idString, out var id))
            currentArticleId = id;
    }
    var article = await _articleService.GetDataAsync(new EntityBaseId { Id = currentArticleId ?? 0 }) ?? new ArtArticleOutDto();
    await _articleService.PlusViewCountAsync(new EntityBaseId { Id = currentArticleId ?? 0 });
    var articleList = await _articleService.GetPagesAsync(new ArticleParam { CategorieIsDisable = YesOrNot.N, TagIds = article.TagIds, PageNo = 1, PageSize = 3 });

    var hortList = _articleService.GetList(new ArticleParam { CategorieIsDisable = YesOrNot.N, PageNo = 1, PageSize = 10 });

    Layout = "_Layout";
    ViewData["Title"] = article.Title;
}
<div class="bl-bgclor container-fluid">
    <div class="bl-banner container">
        <p>@Html.Raw(banner?.Label)</p>
        <div class="banner-img" data-aos="fade-up"><img src="@banner?.ExtData" /></div>
    </div>
</div>
<div class="container">
    <div class="row">
        <div class="col-md-9 col-sm-12">
            <h3 class="bl-artical-title">@Html.Raw(article?.Title)</h3>
            <div class="bl-label">
                @if (article?.CoverImage.NotNullOrWhiteSpace() ?? false)
                {
                    <div class="bl-label-item">
                        <img src="@article?.CoverImage" class="img-fluid rounded-circle bl-img-size" alt="">
                        <span class="text-success">@Html.Raw(article?.Creator)</span>
                    </div>
                 }
                <div class="bl-label-item">@article?.CreateTime?.ToString("yyyy-MM-dd")</div>
            </div>
            <div class="bl-artical">
                @Html.Raw(article?.Content)
            </div>
            <div class="recommend-panel">
                <h4 class="bl-title">相关文章</h4>
                <div class="card-deck">
                    @foreach (var x in articleList.Rows ?? new List<ArtArticleOutDto>())
                    {
                        <div class="card bl-panel">
                            <a href="bl-aritical.html">
                                <div class="recommend-panel-top">
                                    @if (x.CoverImage.NotNullOrWhiteSpace())
                                    {
                                        <img src="@x.CoverImage" class="img-fluid" alt="@Html.Raw(x.Title)">
                                    }
                                </div>
                                <div class="recommend-panel-bottom">
                                    @Html.Raw(x.Title)
                                </div>
                            </a>
                        </div>
                    } 
                </div>
            </div>

           @*
           <div class="comment">
            <h4 class="bl-title">相关评价</h4>
            <form class="bl-comment-form">
            <div class="form-group">
            <textarea class="form-control" placeholder="想说就说吧..." id="exampleFormControlTextarea1" rows="5"></textarea>
            </div>
            <button type="button">发表</button>
            <span class="clearfix"></span>
            </form>
            <div class="comment-panel">
            <div class="comment-panel-portrait"><img src="/lib/img/portrait.jpg" alt=""></div>
            <div class="comment-panel-content">
            <div class="comment-panel-content-item">
            <span>海哥</span>
            <span>2017-10-01 18:00</span>
            </div>
            <p>我上传的是FTP，怎么安装？</p>
            </div>
            <span class="clearfix"></span>
            <p class="bl-reply"><a href="">回复</a></p>
            </div>
            <div class="comment-panel">
            <div class="comment-panel-portrait"><img src="/lib/img/portrait.jpg" alt=""></div>
            <div class="comment-panel-content">
            <div class="comment-panel-content-item">
            <span>海哥</span>
            <span>2017-10-01 18:00</span>
            </div>
            <div class="comment-panel-secondary">
            <span>引用来自于 <span>你要走到那里去</span> 的内容</span>
            <p>稍等，我看看</p>
            </div>
            <p>我上传的是FTP，怎么安装？</p>
            </div>
            <span class="clearfix"></span>
            <p class="bl-reply"><a href="">回复</a></p>
            </div>
            </div>
            *@

        </div>
        <div class="col-md-3 col-sm-12">
            <div class="card-right">
                <h4 class="bl-title">热门文章</h4>
                @foreach (var x in hortList)
                {
                    <div class="card-right-body">
                        <a href="@("/details/"+x.Id+".html")">
                            <div>@if (x.CoverImage.NotNullOrWhiteSpace()){ <img src="@x.CoverImage" class="img-fluid" alt="@Html.Raw(x.Title)"> }</div>
                            <p>@Html.Raw(x.Title)</p>
                        </a>
                    </div>
                }
            </div>
        </div>
    </div>
</div>

@section Scripts
 {
    <script src="~/lib/highlight/highlight.pack.js"></script>
    <script>hljs.initHighlightingOnLoad();</script>
}